import java.util.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.Container;

/**
 *	Homework 10
 * Starter Class
 *
 * This class starts the game, and handles any time the user wants to restart.
 * I worked on the homework assignment alone, using only course materials.
 *
 *  @author Christopher Cheape
 *  @version 1.0 11/30/12
 */
 
public class Starter
{
	/**
	 * Starts the game.
	 */
	public static void main(String[] args)
	{
		Starter.newGame();
	}
	
	/**
	 * Asks the user if they would like to retry. If yes, it starts a new game. If no, it exits.
	 */
	public static void tryAgain(GameController game)
	{
		int reply = JOptionPane.showConfirmDialog(null, "Would you like to play again?","Try again?", JOptionPane.YES_NO_OPTION);
		
    	if (reply == JOptionPane.YES_OPTION)
    	{
      	newGame();
    	}
		else
		{
			System.exit(0);
		}
	}
	
	/**
	 * Starts a new game of Minesweeper, asking the user the dimensions of the game and the number of mines.
	 * It then creates a JFrame with this information.
	 */
	public static void newGame()
	{
		int ex,why;
		int my=0;
		boolean ok=false;
		
		String stringEx = JOptionPane.showInputDialog(null, "Width of the Minesweeper game?");
		ex = Integer.parseInt(stringEx);
		String stringWhy = JOptionPane.showInputDialog(null, "Height of the Minesweeper game?");
		why = Integer.parseInt(stringWhy);
		
		while(ok==false)
		{
			String stringMy = JOptionPane.showInputDialog(null, "Number of mines?");
			my = Integer.parseInt(stringMy);
			if(my<ex*why)
			{
				ok=true;
			}
			else
			{
				JOptionPane.showMessageDialog(null,"Too many mines!");
			}
		}
		
		JFrame frame = new JFrame();
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		GameController game = new GameController(ex,why,my);
		MinePanel gamePanel = new MinePanel(game);
		frame.add(gamePanel);
		frame.pack();
		frame.setVisible(true);
	}
	
	
}